package com.easyattendance.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="tbl_Student_Elective")
@IdClass(StudentElectivePK.class)
public class StudentElective {
	
		@Id
		@Column(name="stud_roll_no",length=3,nullable=false)
		private String stud_roll_no;
		
		@Id
		@Column(name="class_id",length=15,nullable=false)
		private String class_id;
		
		@Id
		@Column(name="subject_id",length=6,nullable=false)
		private String subject_id;
		
		/* Many to one mapping */
		
		@ManyToOne
		@JoinColumns({
		@JoinColumn(name="stud_roll_no", insertable=false, updatable=false, referencedColumnName="stud_roll_no"),
		@JoinColumn(name="class_id", insertable=false, updatable=false, referencedColumnName="class_id")
		})
		private Student student;
		
		@ManyToOne
		@JoinColumn(name="subject_id", insertable=false, updatable=false, referencedColumnName="subject_id")
		private Subject subject;
		
		public StudentElective() {			
		}
		
		public StudentElective(String stud_roll_no, String class_id,
				String subject_id) {
			super();
			this.stud_roll_no = stud_roll_no;
			this.class_id = class_id;
			this.subject_id = subject_id;
		}
		
		

		public StudentElective(String stud_roll_no, Student student, Subject subject) {
			super();
			this.stud_roll_no = stud_roll_no;
			this.student = student;
			this.subject = subject;
		}

		public String getStud_roll_no() {
			return stud_roll_no;
		}

		public void setStud_roll_no(String stud_roll_no) {
			this.stud_roll_no = stud_roll_no;
		}

		public String getClass_id() {
			return class_id;
		}

		public void setClass_id(String class_id) {
			this.class_id = class_id;
		}

		public String getSubject_id() {
			return subject_id;
		}

		public void setSubject_id(String subject_id) {
			this.subject_id = subject_id;
		}

		public Student getStudent() {
			return student;
		}

		public void setStudent(Student student) {
			this.student = student;
		}

		public Subject getSubject() {
			return subject;
		}

		public void setSubject(Subject subject) {
			this.subject = subject;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result
					+ ((class_id == null) ? 0 : class_id.hashCode());
			result = prime * result
					+ ((stud_roll_no == null) ? 0 : stud_roll_no.hashCode());
			result = prime * result
					+ ((subject_id == null) ? 0 : subject_id.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			StudentElective other = (StudentElective) obj;
			if (class_id.equals(other.class_id) && stud_roll_no.equals(other.stud_roll_no) && subject_id.equals(other.subject_id)) {
				return true;
			}
			return false;
		}
		
		
		
		
}
